@extends('layouts.app')
@include('order.sidebar')
@section('content')
    @php
        use Illuminate\Support\Facades\Auth;
        use App\Modules\User\Models\Admin;
        $user = Auth::user();
    @endphp
    <div class="content" style="overflow:auto">
        <div class="row custom-invoice" style="min-width: 1200px">
            <div class="row">
                <form method="get" class="form form-inline" action="{{ route('admin.order.package_index') }}"  autocomplete="off">
                        <div class="form-group" style="margin-left: 15px;">
                            <input style="min-width:250px; max-width: 300px" class="form-control" type="text" name="order_id" value="{{ $orderId }}" placeholder="订单ID">
                        </div>
                        <div class="form-group" style="margin-left: 15px;">
                            <input style="min-width:250px; max-width: 300px" class="form-control" type="text" name="name" value="{{ $name }}" placeholder="姓名">
                        </div>
                        <div class="form-group" style="margin-left: 15px;">
                            <input style="min-width:250px; max-width: 300px" class="form-control" type="text" name="mobile" value="{{ $mobile }}" placeholder="电话号">
                        </div>
                        <div class="form-group" style="margin-left: 15px;">
                            <input style="min-width:250px; max-width: 300px" class="form-control" type="text" name="referrer_name" value="{{ $referrerName }}" placeholder="推荐人">
                        </div>
                        <div class="form-group" style="margin-left: 15px;">
                            <select class="form-control select2" name="shop_id" id="shop_id">
                                @if ($shopId != '')
                                    <option value="{{$shopId}}">{{$shopName}}</option>
                                @else
                                    <option value="">选择门店</option>
                                @endif
                            </select>
                        </div>
                        <br>
                        <div class="form-group" style="margin-top:15px; margin-left: 15px;">
                            <div class="form-group form-inline">
                                <input style="min-width:250px; max-width: 300px" class="form-control" type="text" placeholder="起始时间" id="start" name="start" value="{{ $start }}"/>
                                -
                                <input style="min-width:250px; max-width: 300px" class="form-control" type="text" placeholder="截止时间" id="end" name="end" value="{{ $end }}"/>
                            </div>
                        </div>

                        <div class="form-group" style="margin-top:15px; margin-left: 15px;">
                            <div class="form-group form-inline">
                                <label for="delivery">订单类型: </label>
                                <select class="form-control" name="is_prepay" style="min-width:200px; max-width: 200px">
                                    <option value="" {{ $isPrepay == ""? "selected":"" }}>全部</option>
                                    <option value="0" {{ $isPrepay == "0"? "selected":"" }}>全款订单</option>
                                    <option value="1" {{ $isPrepay == "1"? "selected":"" }}>预付订单</option>
                                </select>
                            </div>
                        </div>
                        {{--                    <div class="form-group col-md-2 col-sm-3 col-xs-10">--}}
                        {{--                        <input type="checkbox" name="status[]" id="statusInit" value="{{ \App\Modules\Order\Models\Order::STATUS_INIT }}" {{ in_array('init', $status)? "checked":"" }}>--}}
                        {{--                        <label class="control-label" for="statusInit">待支付</label>--}}
                        {{--                    </div>--}}
                        {{--                    <div class="form-group col-md-2 col-sm-3 col-xs-10">--}}
                        {{--                        <input type="checkbox" name="status[]" id="statusPaid" value="{{ \App\Modules\Order\Models\Order::STATUS_PAID }}"  {{ in_array('paid', $status)? "checked":"" }}>--}}
                        {{--                        <label class="control-label" for="statusPaid">已支付</label>--}}
                        {{--                    </div>--}}
                        {{--                    <div class="form-group col-md-2 col-sm-3 col-xs-10">--}}
                        {{--                        <input type="checkbox" name="status[]" id="statusRefund" value="{{ \App\Modules\Order\Models\Order::STATUS_REFUND }}"  {{ in_array('refund', $status)? "checked":"" }}>--}}
                        {{--                        <label class="control-label" for="statusRefund">已退款</label>--}}
                        {{--                    </div>--}}
                        {{--                    <div class="form-group col-md-2 col-sm-3 col-xs-10">--}}
                        {{--                        <input type="checkbox" name="status[]" id="statusClose" value="{{ \App\Modules\Order\Models\Order::STATUS_CLOSE }}" {{ in_array('close', $status)? "checked":"" }}>--}}
                        {{--                        <label class="control-label" for="statusClose">已关闭</label>--}}
                        {{--                    </div>--}}
                        {{--                    <div class="form-group col-md-2 col-sm-3 col-xs-10">--}}
                        {{--                        <input type="checkbox" name="is_finish" id="is_finish" value="1" {{ $isFinish ? "checked":"" }}>--}}
                        {{--                        <label class="control-label" for="is_finish">已交付</label>--}}
                        {{--                    </div>--}}
                        <div class="form-group" style="margin-top:15px;">
                            <button class="btn btn-success btn-ms" type="submit">搜索</button>
                            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                                @can('merchant_staff_order_export')
                                    <button class="btn btn-primary btn-ms" type="submit" name="export" value="1">导出</button>
                                @endcan
                            @else
                                @can('package-order-export')
                                    <button class="btn btn-primary btn-ms" type="submit" name="export" value="1">导出</button>
                                @endcan
                            @endif
                        </div>
                </form>
            </div>
            <div class="form-inline" style="margin-top:30px;">
                <div class="form-group" style="font-weight: bold; margin-right: 25px;">订单数量: {{ $count  }}</div>
                <div class="form-group" style="font-weight: bold; margin-right: 25px;">订单价格: {{ $original_price  }}</div>
                <div class="form-group" style="font-weight: bold; margin-right: 25px;">微信支付: {{ $we_chat_pay  }}</div>
                <div class="form-group" style="font-weight: bold; margin-right: 25px;">优惠券: {{ $coupon_pay  }}</div>
                <div class="form-group" style="font-weight: bold; margin-right: 25px;">退款金额: {{ $refund_fee  }}</div>
            </div>
            <hr/>
            <br/>
            <div style="overflow: hidden;overflow-x: scroll;width: 1550px; -transform: scaleY(-1);">
                <table class="table table-striped table-hover" style="-width: 2100px !important;max-width: 2500px !important; -transform: scaleY(-1);">
                    <thead>
                    <tr>
                        <th style="min-width: 100px;">订单ID</th>
                        <th style="min-width: 150px;">下单时间</th>
                        <th style="min-width: 150px;">用户</th>
                        <th style="min-width: 60px;">头像</th>
                        <th style="min-width: 250px;">套系名</th>
                        <th style="min-width: 350px;">所选产品</th>
                        <th style="min-width: 100px;">订单价格</th>
                        <th style="min-width: 100px;">微信支付</th>
                        <th style="min-width: 100px;">优惠券</th>
                        <th style="min-width: 100px;">状态</th>
                        <th style="min-width: 100px;">尾款信息</th>
                        <th style="min-width: 100px;">预约时间</th>
                        <th style="min-width: 100px;">顾客姓名</th>
                        <th style="min-width: 100px;">电话号</th>
                        <th style="min-width: 100px;">退款金额</th>
                        <th style="min-width: 100px;">推荐人</th>
                        <th style="min-width: 150px;">买家备注</th>
                        <th style="min-width: 400px;">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($data as $item)
                        <tr>
                            <td>{{ $item->id }}</td>
                            <td>{{ $item->created_at }}</td>
                            <td>{{ $item->nickname }}</td>
                            <td>
                                <img src="{{ $item->avatar  }}" width="30">
                            </td>
                            <td>{{ $item->title }}</td>
                            <td>{!! $item->spec !!}</td>
                            <td>{{ $item->original_price/100 }}</td>
                            <th>{{ $item->we_chat_pay/100 }}</th>
                            <th>{{ $item->coupon_pay/100 }}</th>
                            <td>{{ \App\Modules\Order\Models\Order::$statusShow[$item->status] }}</td>
                            <td>{{ $item->is_prepay? ($item->final_payment ? "尾款已收" : "未收尾款"):"全款订单" }}</td>
                            <td>{{ $item->deliver_date }}</td>
                            <td>{{ $item->name }}</td>
                            <td>{{ $item->mobile }}</td>
                            <td>{{ $item->refund_fee/100 }}</td>
                            <td>{{ $item->referrer_name }}</td>
                            <td>{{ $item->buyer_remark }}</td>
                            <td>
                                <a class="btn btn-default btn-xs" onclick="getAddress({{ $item->id }})">查看收货信息</a>
                                <div class="modal fade loading custom-hide" id="hideAddressForm_{{ $item->id }}"
                                     tabindex="-1" role="dialog"
                                     aria-labelledby="hideFormLibel" aria-hidden="true" data-backdrop="static"
                                     data-keyboard="false">
                                    <div class="modal-dialog">
                                        <div class="content invoice" style="text-align: left">
                                            <span onclick="closeAddress({{ $item->id }})" class="span-X"><i
                                                    class="fa fa-close"></i></span>
                                            <div class="form-group">
                                                <label for="name">收货人：</label>
                                                {{ $item->name}}
                                            </div>
                                            <div class="form-group">
                                                <label for="mobile">手机号：</label>
                                                {{ $item->mobile}}
                                            </div>
                                            <div class="form-group">
                                                <label for="address">地址：</label>
                                                {{ $item->address}}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                                    @if($item->status == \App\Modules\Order\Models\Order::STATUS_PAID && !$item->buyer_confirm)
                                        @can('merchant_staff_order_refund')
                                            <a class="btn btn-danger btn-xs refund"
                                               data-url="{{ route("admin.order.refund", ['id' => $item->id]) }}"><i
                                                    class="fa fa-recycle"></i> 退款</a>
                                        @endcan
                                        @can('merchant_staff_order_success')
                                            @if(!$item->is_finish)
                                                <a class="btn btn-success btn-xs"
                                                   href="{{ route('admin.order.finish', ['id' => $item->id]) }}"><i
                                                        class="fa fa-star"></i> 标记完成</a>
                                            @endif
                                        @endcan
                                    @endif

                                    @can('merchant_staff_order_change')
                                        @if($item->status == \App\Modules\Order\Models\Order::STATUS_INIT)
                                            <a class="btn btn-danger btn-xs change-price"
                                               data-url="{{ route("admin.order.change_price", ['id' => $item->id]) }}"><i
                                                    class="fa fa-money"></i> 修改价格</a>
                                        @endif
                                    @endcan

                                    @if(!empty($item->bill))
                                        <a class="btn btn-info btn-xs show-bill" data-image="{{ $item->bill }}"><i
                                                class="fa fa-file-image-o"></i> 查看凭证</a>
                                    @endif

                                    @can('merchant_staff_order_closing_payment')
                                        @if(!$item->final_payment && $item->status == App\Modules\Order\Models\Order::STATUS_PAID)
                                            <a class="btn btn-success btn-xs"
                                               href="{{ route('admin.order.final_payment', ['id' => $item->id]) }}"><i
                                                    class="fa fa-star"></i> 收尾款</a>
                                        @endif
                                    @endcan
                                    @can('merchant_staff_order_change')
                                        @if($item->status == \App\Modules\Order\Models\Order::STATUS_CLOSE)
                                            <a class="btn btn-danger btn-xs delete-confirm"
                                               data-href="{{ route('admin.order.delete', ['id' => $item->id]) }}"><i
                                                    class="fa fa-trash-o"></i> 删除</a>
                                        @endif
                                    @endcan

                                @else
                                    @if($item->status == \App\Modules\Order\Models\Order::STATUS_PAID && !$item->buyer_confirm)
                                        @can('package-order-refund')
                                            <a class="btn btn-danger btn-xs refund"
                                               data-url="{{ route("admin.order.refund", ['id' => $item->id]) }}"><i
                                                    class="fa fa-recycle"></i> 退款</a>
                                        @endcan
                                        @can('package-order-finish')
                                            @if(!$item->is_finish)
                                                <a class="btn btn-success btn-xs"
                                                   href="{{ route('admin.order.finish', ['id' => $item->id]) }}"><i
                                                        class="fa fa-star"></i> 标记完成</a>
                                            @endif
                                        @endcan
                                    @endif
                                    @can('package-order-change')
                                        @if($item->status == \App\Modules\Order\Models\Order::STATUS_INIT)
                                            <a class="btn btn-danger btn-xs change-price"
                                               data-url="{{ route("admin.order.change_price", ['id' => $item->id]) }}"><i
                                                    class="fa fa-money"></i> 修改价格</a>
                                        @endif
                                    @endcan
                                    @if(!empty($item->bill))
                                        <a class="btn btn-info btn-xs show-bill" data-image="{{ $item->bill }}"><i
                                                class="fa fa-file-image-o"></i> 查看凭证</a>
                                    @endif
                                    @can('package-order-final')
                                        @if(!$item->final_payment && $item->status == App\Modules\Order\Models\Order::STATUS_PAID)
                                            <a class="btn btn-success btn-xs"
                                               href="{{ route('admin.order.final_payment', ['id' => $item->id]) }}"><i
                                                    class="fa fa-star"></i> 收尾款</a>
                                        @endif
                                    @endcan
                                    @can('package-order-change')
                                        @if($item->status == \App\Modules\Order\Models\Order::STATUS_CLOSE)
                                            <a class="btn btn-danger btn-xs delete-confirm"
                                               data-href="{{ route('admin.order.delete', ['id' => $item->id]) }}"><i
                                                    class="fa fa-trash-o"></i> 删除</a>
                                        @endif
                                    @endcan
                                @endif

                            </td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
            {{ $data->appends(request()->all())->links() }}
        </div>
        <div class="modal fade loading custom-hide" id="hideForm" tabindex="-1" role="dialog"
             aria-labelledby="hideFormLibel" aria-hidden="true" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="content invoice" style="text-align: left">
                    <form class='form' action="" method="POST">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                        <div class="form-group">
                            <label for="money">金额：</label>
                            <input class="form-control" type="text" name="money" id="money" required/>
                        </div>
                        <div class="form-group">
                            <label for="reason">理由：</label>
                            <input class="form-control" type="text" name="reason" id="reason" required/>
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-success form-control">提交</button>
                            <br/>
                            <br/>
                            <button type="button" class="btn" id="closeHideForm">关闭</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <div class="modal fade loading custom-hide" style="width: 100%;text-align: center" id="hideForm2" tabindex="-1"
             role="dialog" aria-labelledby="hideFormLibel" aria-hidden="true" data-backdrop="static"
             data-keyboard="false">
            <div class="content invoice" style="position: relative; width: 60%; margin: auto">
                <span id="closeHideForm2" class="span-X"><i class="fa fa-close"></i></span>
                <div class="row" id="image-content">
                </div>
            </div>
        </div>
    </div>
@endsection
@push('stylesheets')
    <style>
        .span-X {
            position: absolute;
            border-radius: 50px;
            top: 10px;
            right: 10px;
            padding: 3px 5px;
            line-height: 0;
            background-color: rgba(190, 190, 190, 0.50);
        }
    </style>
@endpush
@push('scripts')
    <script>

        $(".select2#shop_id").select2({
            width:"250px",
            ajax: {
                dataType: 'json',
                delay: 250,
                url: function () {
                    return '{{ route('admin.order.search_shops', ['is_photography' => 1]) }}';
                },
                processResults: function (data) {
                    return {
                        results: $.map(data, function (row, key) {
                            return {
                                id: key,
                                text: row,
                            };
                        })
                    };
                }
            }
        });

        $('#start').datetimepicker({format: "Y-m-d",timepicker:false});
        $('#end').datetimepicker({format: "Y-m-d",timepicker:false});
        // $('#start').attr('readonly', 'readonly');
        // $('#end').attr('readonly', 'readonly');
        $.datetimepicker.setLocale('zh');

        $('.refund').on('click', function () {
            $("#hideForm form").attr('action', $(this).attr('data-url'));
            $("#hideForm").modal('show');
        });
        $('#closeHideForm').on('click', function () {
            $("#hideForm").modal('hide');
        });

        $('.change-price').on('click', function () {
            $("#hideForm form").attr('action', $(this).attr('data-url'));
            $("#hideForm").modal('show');
        });


        $('.show-bill').on('click', function () {
            var k = $(this).attr('data-image').split(";");
            node = "";
            for (index in k) {
                node += "<div style= \"float:left;width: 200px;margin: 10px;\">\n" +
                    "       <img src=\"" + k[index] + "\" width='100%'>\n" +
                    "   </div>";
            }
            $('#image-content').html(node);
            $("#hideForm2").modal('show');
        });
        $('#closeHideForm2').on('click', function () {
            $("#hideForm2").modal('hide');
        });

        function getAddress(id) {
            $("#hideAddressForm_" + id).modal('show');
        }

        function closeAddress(id) {
            $("#hideAddressForm_" + id).modal('hide');

        }

    </script>
@endpush


